<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/9/29
 * Time: 20:49
 */

include_once 'common.php';// 引入公共函数

session_start();// 开启session
$sessionId = 'redis_session_' . session_id();// session的id

$redis = new Redis();//redis实例
$redis->connect('127.0.0.1', 6379);//连接redis
$redis->auth('riven');// 连接redis密码

$redisSessionTime = 3600;// redis_session时效
$param = ['/index.php', '/register.php', '/login.php', '/doLogin.php'];

$userInfo = $redis->hGetAll($sessionId);//用户session信息
//检测是否登录
if (empty($userInfo) && !in_array($_SERVER['PHP_SELF'], $param)) {//未登录跳转登录
    notice('请先登录', 'login.php');
}

if (!empty($userInfo) && in_array($_SERVER['PHP_SELF'], $param)) {
    header('location: main.php');//已登录跳转主页面
}

header('Content-Type:text/html; charset=utf-8');// 设置页面编码为utf8
?>
<script type="text/javascript">
    function jump_url(url) {
        window.location.href = url;
    }
</script>
